//
//  HomePageViewController.m
//  HomeFinder
//
//  Created by 蒋永昌 on 16/2/25.
//  Copyright © 2016年 蒋永昌. All rights reserved.
//

#import "HomePageViewController.h"
#import "HomepageCell.h"

#define kWidth self.view.frame.size.width
#define kHeight self.view.frame.size.height
@interface HomePageViewController ()<UITableViewDelegate,UITableViewDataSource,UISearchBarDelegate>
@property (nonatomic,strong) UITableView*myTableView;
@property (nonatomic,strong)UISearchBar *mySearchBar;
@property (nonatomic,strong) UIImageView *topImageView;
@property (nonatomic,strong) UIButton *privateBtn;
@property (nonatomic,strong)UIButton *mediuBtn;

@end

@implementation HomePageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
   
    //添加顶部图片
    self.topImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"top5.jpg"]];
    self.topImageView.frame = CGRectMake(0, 0, kWidth, kHeight*0.45);
    self.topImageView.userInteractionEnabled = YES;
    [self.view addSubview:self.topImageView];
    //添加一个searchBar
    self.mySearchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0, 22, kWidth, kHeight*0.05)];
//    self.mySearchBar.barTintColor = [UIColor clearColor];
    [self.mySearchBar setPlaceholder:@"请输入想找的商圈/地铁/小区"];
    self.mySearchBar.alpha = 0.5;
    [self.topImageView addSubview:self.mySearchBar];
    //添加button
    self.privateBtn = [UIButton buttonWithType:(UIButtonTypeSystem)];

    self.privateBtn.frame = CGRectMake(0, kHeight*0.37, kWidth*0.495, kHeight*0.08);
    self.privateBtn.backgroundColor = [UIColor grayColor];
    self.privateBtn.alpha = 0.5;
    
    [self.privateBtn setTitle:@"私人订制" forState:UIControlStateNormal];

    [self.privateBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
     [self.privateBtn addTarget:self action:@selector(privateBtnClicked) forControlEvents:(UIControlEventTouchUpInside)];
    [self.topImageView addSubview:self.privateBtn];
    
    self.mediuBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    [self.mediuBtn setTitle:@"中介找房" forState:(UIControlStateNormal)];
    [self.mediuBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];

    [self.mediuBtn addTarget:self action:@selector(mediuBtnClicked) forControlEvents:(UIControlEventTouchUpInside)];

    self.mediuBtn.frame = CGRectMake(kWidth*0.505, kHeight*0.37, kWidth*0.495, kHeight*0.08);
    self.mediuBtn.backgroundColor = [UIColor grayColor];
    self.mediuBtn.alpha = 0.5;
    [self.topImageView addSubview:self.mediuBtn];
    //添加tableViewCell
    self.myTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, kHeight*0.45, kWidth, kHeight*0.5) style:(UITableViewStylePlain)];
    [self.view addSubview:self.myTableView];
    //注册cell
    [self.myTableView registerClass:[HomepageCell class] forCellReuseIdentifier:@"homepagecell"];
    self.myTableView.delegate = self;
    self.myTableView.dataSource = self;
    
    self.view.backgroundColor = [UIColor cyanColor];
    
    // Do any additional setup after loading the view.
}
#pragma mark  ======= 给button添加事件 ========
- (void)privateBtnClicked
{
    NSLog(@"sdf");
}
- (void)mediuBtnClicked{
    
}

#pragma mark ========== searchBarDelgate ========
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText{
    
}

#pragma mark ========== tableView DataSource and Delegate ====

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    HomepageCell *cell = [self.myTableView dequeueReusableCellWithIdentifier:@"homepagecell" forIndexPath:indexPath];
    
    return cell;
}
//设置行高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 130;
}
//设置每个区域有多少行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 10;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 25;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    NSString *string = @"精品推荐";
    return string;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self.mySearchBar resignFirstResponder];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
